<%--
  User: yealove
  Date: 9/14/14
  Time: 15:04 PM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:import url="../common/include.jsp"/>
    <title>团队订餐统计系统</title>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-xs-12 col-md-6 col-xs-offset-1">
            <div class="h3">历史：</div>
            <div class="row table-responsive">
                <table class="table table-hover table-condensed">
                    <tr>
                        <th>#</th>
                        <th>日期</th>
                        <th>菜名</th>
                        <th>备注</th>
                        <th>金额</th>
                        <th>操作</th>
                    </tr>
                    <c:if test="${orders != null}">
                        <c:forEach items="${orders}" var="order" varStatus="s">
                            <tr>
                                <td>${s.index+1}</td>
                                <td>${order.createDate}</td>
                                <td>${order.menuName}</td>
                                <td>${order.memo}</td>
                                <td>${order.price}</td>
                                <td>
                                    <script>
                                        var time = "${order.createDate}";
                                        var m = time.substr(0, 2);
                                        var d = time.substr(3, 2);
                                        var date = new Date();
                                        if (m == date.getMonth() + 1 && d == date.getDate() && '${order.flag}' == 'd' && '${eatThat.status}' == '1') {
                                            document.write("<button class='btn btn-primary btn-xs' onclick='delOrder(${order.id})')'>退订 </button>");
                                        }
                                    </script>
                                </td>
                            </tr>
                        </c:forEach>
                    </c:if>
                    <c:if test="${orders == null}">
                        <tr>
                            <td colspan="4" style="text-align: center">无记录</td>
                        </tr>
                    </c:if>
                </table>
            </div>
        </div>
        <div class="col-xs-12 col-md-4 col-xs-offset-1" style="border-left: rgba(0, 0, 0, 0.2) solid 1px">
            <div class="h4">个人信息：</div>
            <div class="row table-responsive col-xs-offset-1" id="orders">
                <table class="table table-hover table-condensed">
                    <tr>
                        <td>真实姓名：</td>
                        <td>${user_info.name}</td>
                    </tr>
                    <tr>
                        <td>账号：</td>
                        <td>${user_info.username}</td>
                    </tr>
                    <tr>
                        <td>余额：</td>
                        <td>
                            <script>
                                var money = parseInt("${user_info.money}");
                                var html = money;
                                if (money < 0) {
                                    html = "<span style='color: red'>" + money + "</span>"
                                }
                                document.write(html);
                            </script>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    pay = function (id) {
        $.ajax({url: "/lunchparty/pay.do", data: "dictid=" + id + "&dictname=" + $("#" + id).val(), type: "post", success: function (data) {
            $("#m" + id).html(data);
        }});
    }

    delOrder = function (id) {
        $.ajax({url: "/lunchparty/eatThat.do", data: "id=" + id, type: "post", success: function (data) {
            if(data == "success") {
                layer.msg("退订成功！", 2, {type: 10});
                window.location.reload();
            } else if(data == "eatThat_close"){
                layer.msg("现在不能退订了，如有需要请订餐负责人！", 8, {type: 10});
                window.location.reload();
            } else {
                layer.alert("退订失败，如有需要请联系管理员！", 8);
            }
        }});
    }
</script>
</body>
</html>